<?php
/*----------------------------------------------------------------------
#Youjoomla Title Ticker
# ----------------------------------------------------------------------
# Copyright (C) 2007 You Joomla. All Rights Reserved.
# Designed by: Youjoomla.com
# GNU
# Website: http://www.youjoomla.com// Copyright (c) 2006 - 2008 Youjoomla LLC
# This code cannot be redistributed without permission from Youjoomla - http://www.youjoomla.com.
# More info at http://www.youjoomla.com 
# Developer: Dragan Todorovic
------------------------------------------------------------------------*/

  
 defined('_JEXEC') or die('Restricted access');
require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
$database					=& JFactory::getDBO();
$mosConfig_absolute_path	= JPATH_ROOT;
$mosConfig_live_site 		= JURI :: base();    
   

global $mosConfig_absolute_path, $mosConfig_live_site, $mainframe, $database, $_MAMBOTS;



$mootools=$params->get('mootools',"0");
$compress=$params->get('compress',"0");
	
if($compress ==1 ){
$mooext= 'php';
}else{
$mooext= 'js';
}

  echo "<!-- http://www.Youjoomla.com  Youjoomla Title Ticker  for Joomla 1.5 starts here -->	";


if ($mootools == 1){
echo '<script src="modules/mod_yj_nt2/lib/mootools.'.$mooext.'" type="text/javascript"></script>';

  }else{}

?>

		
        
<?php

        
        
  $now 		    = date('Y-m-d H:i:s');
  $database 	=& JFactory::getDBO();
  $nullDate 	= $database->getNullDate();


 
  

//db///
$get_items = $params->get('get_items',1);
$nitems = $params->get ('nitems',5);
//////mod ///
$width = $params->get ('width','150px');
$height = $params->get ('height','20px');
$textalig = $params->get ('textalig','center');
$bg = $params->get ('bg','transparent');
$show_title = $params->get ('show_title','1');
$title_w = $params->get ('title_w','90px');
$title_text = $params->get ('title_text','Fresh Press');
$color = $params->get ('color','#000');
$time = $params->get ('time',5000);
$duration = $params->get ('duration',1000);
$orient = $params->get ('orient','1');
$type = $params->get ('type','scroll'); // scroll  | fade | scrollfade

$shownav  = $params->get ('shownav','1');

$ordering = $params->get('ordering',1);// 1 = ordering | 2 = popular | 3 = random 

////////////////////////// /BRAKE YOUR BRAIN! I BROKE MINE :) //////////////////////////////////


if($ordering ==1){
$order = 'ordering';
}elseif($ordering == 2){
$order = 'hits';
}elseif ($ordering == 3){
$order = 'RAND()';
}

///functions//

if($orient == 1){
$float = "float:left;";
$upd = "width";
}else{
$float ="";
$upd = "height";
}


if ($shownav == 1 ){
$hold_w = $title_w + $width + 30;
}elseif ($show_title == 1){
$hold_w = $title_w + $width;
}else{
$hold_w = $width + 0;
}



$main_w = $width * $nitems ;


		$db			=& JFactory::getDBO();
		$user		=& JFactory::getUser();
		$userId		= (int) $user->get('id');
		$aid		= $user->get('aid', 0);

		$contentConfig = &JComponentHelper::getParams( 'com_content' );
		$access		= !$contentConfig->get('shownoauth');

		$nullDate	= $db->getNullDate();

		$date =& JFactory::getDate();
		$now = $date->toMySQL();

		$where		= 'a.state = 1'
			. ' AND ( a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).' )'
			. ' AND ( a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).' )'
			;



$sql = 'SELECT a.*, ' .
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'. 
' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'.
			' FROM #__content AS a' .
			' INNER JOIN #__categories AS cc ON cc.id = a.catid' .
			' INNER JOIN #__sections AS s ON s.id = a.sectionid' .
			' WHERE '. $where .' AND cc.id = '.$get_items.'' .
			($access ? ' AND a.access <= ' .(int) $aid. ' AND cc.access <= ' .(int) $aid. ' AND s.access <= ' .(int) $aid : '').
			' AND s.published = 1' .
			' AND cc.published = 1' .
			' ORDER BY '.$order .' LIMIT 0,'.$nitems.'';
			
			
$database->setQuery( $sql );
$load_titles = $database->loadObjectList();

//     $Itemid =  $mainframe->getItemid($row->id);
//     if ($Itemid == NULL) {
//   	    $Itemid = '';
//     } else {
//	    $Itemid = '&amp;Itemid='. $Itemid;
//     }
?>
<?php echo '<script src="modules/mod_yj_nt2/lib/titleslide.'.$mooext.'" type="text/javascript"></script>'; ?>


<div id="titles_holder" style="background:<?php echo $bg?>;width:<?php echo $hold_w?>px; height:<?php echo $height?>; overflow:hidden;float:left; text-align:center;">
<?php if($show_title == 1) { ?>
<div id="title_title" style="color:<?php echo $color ?>; font-weight:bold;float:left;line-height:<?php echo $height -1?>px; width:<?php echo $title_w ?>;text-align:center;"><?php echo $title_text ?> :</div><?php } ?>

			<div id="yj_nt2" class="title_slide" style="width:<?php echo $width?>;height:<?php echo $height?>; overflow:hidden; float:left; text-align:center;">
                  
                  <?php  if ($orient == 1 ) { ?>
                  <div style="width:<?php echo $main_w?>px;overflow: hidden;float: left;text-align:<?php echo $textalig?>">
                  <?php } ?>
                   <?php  if ($orient == 0 ) { ?>
                  <div style="height:<?php echo $main_w?>px;overflow: hidden;text-align:<?php echo $textalig?>">
<?php } ?>
              
   <?php


foreach ( $load_titles as $row ) {

$link = ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid);
//$intro 	= substr(strip_tags($row->introtext),0,$chars)."...";
$tpad = $height -0 ;
echo "<div style=\"width:".$width.";line-height:".$tpad."px;text-indent:5px;height:".$height.";".$float ."text-align:".$textalig.";\">";
echo "<a href=\"".JRoute::_($link)."\">".$row->title."</a><br />";
echo "</div>\n";
}


?>







         
</div>
</div> <?php if ($shownav == 1 ){ ?>
<div id="title_nav" style="float:left; width:30px;height:<?php echo $height?>;padding: 0px; margin:0;"><a onclick="javascript: title_slider.prev(type_slider);" ><img src="modules/mod_yj_nt2/images/prev.png" alt="Previous" title="Previous" /></a>&nbsp;<a onclick="javascript: title_slider.next(type_slider);"><img src="modules/mod_yj_nt2/images/next.png" alt="Next" height="7px" width="7px" style="margin-top:<?php echo $height / 2 -3 ?>px" title="Next"  /></a>
</div><?php } ?>
</div>

<script type='text/javascript'>
var  title_slider = new TitleTicker("yj_nt2",{type: "<?php echo $type ?>", direction: "forward", auto: "loop", time: <?php echo $time ?>, duration: <?php echo $duration ?>});
var type_slider='<?php echo $type ?>';
$('titles_holder').addEvent('mouseenter', function(){title_slider.pause();});
$('titles_holder').addEvent('mouseleave', function(){title_slider.run(type_slider);});
</script>
